package com.web.dao.impl;


import com.entity.Festival;
import com.mapper.FestivalMapper;
import com.page.PageInfo;
import com.web.dao.FestivalDao;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("FestivalDao")
public class FestivalDaoImpl implements FestivalDao {
    @Resource
    FestivalMapper festivalMapper;
    /*
    查询全部
     */
    public List<Festival> getAll() throws Exception {
        return festivalMapper.getAll();
    }

    public  Festival selectByPrimaryKey(int fid) throws Exception {
        return festivalMapper.selectByPrimaryKey(fid);
    }

    public  Festival selectByPrimaryKeyWithActivitytype(int fid) throws Exception {
        return festivalMapper.selectByPrimaryKeyWithActivitytype(fid);
    }
    /**
     *分页查询
     * @param pageInfo
     * @return
     */
      public List<Festival> getFestivalsByPage(PageInfo pageInfo) throws Exception {
      Map<String,Object> map = new HashMap<String,Object>();
      map.put("currPage",pageInfo.getCurrPage());
      map.put("pageSize",pageInfo.getPageSize());

      int itemCount = (int)festivalMapper.countByExample(null);
      pageInfo.setItemCount(itemCount);
      return festivalMapper.getFestivalsByPage(map);
  }
    /*
    增加
     */
    public int add(Festival festival) throws Exception {
        return festivalMapper.insertSelective(festival);
    }

    public int update(Festival festival) throws Exception {
        return festivalMapper.updateByPrimaryKeySelective(festival);
    }
}
